package org.carl.dual;

import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Executors;
import java.util.concurrent.locks.Lock;

import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;

public class GuavaThreadHelper {
	public static final int AVAILABLEPROCESSORS = Runtime.getRuntime().availableProcessors();
	// 线程池
	public static ListeningExecutorService listeningExecutorService;
	public static ThreadLocal<Lock> lockThreadLocal;

	static {
		listeningExecutorService=MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
	}
	public static List<ListenableFuture<?>> submit(List<Callable<?>> callables){
		Preconditions.checkNotNull(callables);
		List<ListenableFuture<?>> listenableFutures=new CopyOnWriteArrayList<>();
			callables.forEach((r) -> {
				listenableFutures.add(listeningExecutorService.submit(r));
			});
		return listenableFutures;
	} 
}
